package com.controller;

import com.pojo.Dept;
import com.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("org/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 添加部门
     */
    @PostMapping
    public String addDept(@RequestBody Dept dept){
        return deptService.addDept(dept)>0 ? "操作成功" : "操作失败";
    }

    /**
     *  查询所有部门
     */
    @GetMapping
    public List<Dept> selectAllDept(){
        return deptService.selectAllDept();
    }

    /**
     * 根据条件查询
     */
    @GetMapping("/{deptname}/{deptencode}")
    public  List<Dept> selectDeptByCondition(@PathVariable String deptname,@PathVariable String deptencode){
        Dept dept = new Dept();
        dept.setD_encode(deptencode);
        dept.setD_name(deptname);
        return deptService.selectDeptByCondition(dept);
    }
    /**
     * 修改信息
     */
    @PutMapping
    public String updateDept(@RequestBody Dept dept){
        return deptService.updateDept(dept)>0 ? "操作成功" : "操作失败";
    }
    /**
     * 删除信息
     */
    @DeleteMapping("/{deptName}")
    public  String deleteDept(@PathVariable String deptName){
        return deptService.deleteDept(deptName)>0 ? "操作成功": "操作失败";
    }
}
